package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.service.impl.NursingProjectServiceImpl;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;
    @Autowired
    private NursingProjectServiceImpl nursingProjectServiceImpl;

    /**
     * 分页查询
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称")  String name,
            @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingProjectVo> byPage = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return success(byPage);
    }

    /**
     * 新增项目
     * @param NursingProjectDto
     * @return
     */
    @PostMapping()
    @ApiOperation("新增护理项目")
    public ResponseResult addNursingProject(@ApiParam("新增护理项目信息") @RequestBody NursingProjectDto NursingProjectDto) {
        nursingProjectService.addNursingProject(NursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getById(@ApiParam("护理项目id") @PathVariable Long id) {
        return success(nursingProjectService.getById(id));
    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult updateNursingProject(@ApiParam("修改护理项目信息") @RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteNursingProject(@PathVariable Long id) {
        nursingProjectService.deleteNursingProject(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理项目状态")
    public ResponseResult updateNursingProjectStatus(
           @ApiParam("护理项目id") @PathVariable Long id,
           @ApiParam("状态：0-禁用，1-启用") @PathVariable Integer status) {
        nursingProjectService.updateNursingProjectStatus(id, status);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> getAllNursingProject() {
        List<NursingProjectVo> nursingProjectVoList= nursingProjectService.getAllNursingProject();
        return success(nursingProjectVoList);
    }
}